// program/pages/agent/plugins/superWorkOrder/list/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    config: {},
    workOrderTypeList: [],
    shareAppMessageTitle: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    options.pageName && (wx.setNavigationBarTitle({
      title: options.pageName,
    }),this.setData({shareAppMessageTitle: options.pageName}))
  },

  // 获取工单设置
  loadWorkOrderConfig() {
    var that = this;
    var params = {
      point_url: app.server.agentApi.getSuperWorkOrderConfig
    }
    app.server.getConnect(params).then(function (res) {
      that.setData({
        config: res.data
      })
      that.loadWorkOrderTypeList();
    })
  },

  // 获取工单列表
  loadWorkOrderTypeList() {
    var that = this;
    var params = {
      point_url: app.server.agentApi.getSuperWorkOrderTypeList
    }
    app.server.getConnect(params).then(function (res) {
      that.setData({
        workOrderTypeList: res.data.serverList
      })
    })
  },

  toCreate(e) {
    wx.navigateTo({
      url: '/pages/agent/plugins/superWorkOrder/create/index?id='+e.currentTarget.dataset.id+'&typeName='+e.currentTarget.dataset.name,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    app.pageOnloadInit(this, app);
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1,
        selectedColor: app.globalData.config['selectedColor'],
        list: app.globalData.config['selectedTarbarType'] === 'Admin' ? app.globalData.config.AdminTarbarList : app.globalData.config.AgentTarbarList
      })
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadWorkOrderConfig();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    app.utils.initAgentWxappStyle(app, this);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})